// DocumentPropertiesDialog.cpp : implementation file
//

#include "stdafx.h"
#include "waveeditor.h"
#include "DocumentPropertiesDialog.h"


// DocumentPropertiesDialog dialog

IMPLEMENT_DYNAMIC(DocumentPropertiesDialog, CDialog)
DocumentPropertiesDialog::DocumentPropertiesDialog(CWnd* pParent /*=NULL*/)
	: CDialog(DocumentPropertiesDialog::IDD, pParent)
{
}

DocumentPropertiesDialog::~DocumentPropertiesDialog()
{
}

void DocumentPropertiesDialog::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_COMPRESSIONSTEP, compressionstepctrl);
	compressionstepctrl.SetCurSel(compressionstep);
	DDX_Control(pDX, IDC_EE, efectiveedgectrl);
	efectiveedgectrl.SetCurSel(efectiveedge);
	DDX_Control(pDX, IDC_TWOPATH, twopathctrl);
	twopathctrl.SetCheck(twopath);
}


BEGIN_MESSAGE_MAP(DocumentPropertiesDialog, CDialog)
	ON_BN_CLICKED(IDOK, OnBnClickedOk)
END_MESSAGE_MAP()


// DocumentPropertiesDialog message handlers

void DocumentPropertiesDialog::OnBnClickedOk()
{
	// TODO: Add your control notification handler code here
	compressionstep	=	compressionstepctrl.GetCurSel();
	twopath			=	twopathctrl.GetCheck();
	efectiveedge	=	efectiveedgectrl.GetCurSel();
	OnOK();
}


// myPhaseDriveDilaog dialog
//--------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------
// myPhaseDriveDilaog message handlers
//--------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------

IMPLEMENT_DYNAMIC(myPhaseDriveDilaog, CDialog)
myPhaseDriveDilaog::myPhaseDriveDilaog(mymessages* list,CWnd* pParent /*=NULL*/)
	: CDialog(myPhaseDriveDilaog::IDD, pParent)
	, paramlist(NULL)
	, numbertoshow(_T(""))
{
	paramlist	=	list;
}

myPhaseDriveDilaog::~myPhaseDriveDilaog()
{
}

void myPhaseDriveDilaog::DoDataExchange(CDataExchange* pDX)
{
	StartOnNotify	= 0;
	CDialog::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_PHASENUMBER, number_in_ns);
	DDX_Control(pDX, IDC_PHASELIST, mphaselist);


	int	numberofblocks	=	paramlist->GetNumberOfMessages()/2;
	mphaselist.InsertColumn(0,"TYPE",LVCFMT_LEFT,50,1);
	mphaselist.InsertColumn(1,"Number in ms",LVCFMT_LEFT,40,1);
	mphaselist.SetExtendedStyle(LVS_EX_FULLROWSELECT);
	for(int i=0;i<numberofblocks;i++)
	{
		mphaselist.InsertItem(i,paramlist->GetMessage(i*2));
		mphaselist.SetItemText(i,0,paramlist->GetMessage(i*2));
		mphaselist.SetItemText(i,1,paramlist->GetMessage(i*2+1));
	}
	StartOnNotify	= 1;
}


BEGIN_MESSAGE_MAP(myPhaseDriveDilaog, CDialog)
	ON_BN_CLICKED(IDC_UPDATE, OnBnClickedUpdate)
	ON_NOTIFY(HDN_ITEMCLICK, 0, OnHdnItemclickPhaselist)
END_MESSAGE_MAP()




void myPhaseDriveDilaog::OnBnClickedUpdate()
{
	// TODO: Add your control notification handler code here
}

void myPhaseDriveDilaog::OnHdnItemclickPhaselist(NMHDR *pNMHDR, LRESULT *pResult)
{
	LPNMHEADER phdr = reinterpret_cast<LPNMHEADER>(pNMHDR);
	// TODO: Add your control notification handler code here
	*pResult = 0;

}

BOOL myPhaseDriveDilaog::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
{
	// TODO: Add your specialized code here and/or call the base class
	BOOL ret	=	CDialog::OnNotify(wParam, lParam, pResult);
	if(StartOnNotify == 1)
	{
		OnItemSelect();
	}
	return ret;
}

int myPhaseDriveDilaog::OnItemSelect(void)
{
	StartOnNotify	= 0;
	POSITION pos = mphaselist.GetFirstSelectedItemPosition();
	int selection= mphaselist.GetNextSelectedItem(pos);
	if(selection < 0)
	{
		StartOnNotify	= 1;
		return 1;
	}
	numbertoshow	=	mphaselist.GetItemText(selection,1);
	UpdateData(FALSE);
	StartOnNotify	= 1;
	return 0;
}
